package com.anxin.registerManagement.controller;

import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject;
import com.anxin.registerManagement.bean.jo.SceneSearchJo;
import com.anxin.registerManagement.bean.persist.Scene;
import com.anxin.registerManagement.service.SceneService;
import com.anxin.registerManagement.util.Assert;
import com.anxin.registerManagement.util.ResultUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author anxin
 * @date 2022/3/30 19:25
 */
@RestController
@RequestMapping("/scenes")
public class SceneController {

    private static final Logger LOGGER = LoggerFactory.getLogger(SceneController.class);

    @Autowired
    private SceneService sceneService;

    @PostMapping("/search")
    public ResultUtil search(@RequestBody SceneSearchJo sceneSearchJo) {
        return ResultUtil.success(sceneService.searchScene(sceneSearchJo));
    }

    @PostMapping("/create")
    public ResultUtil create(@RequestBody Scene scene) {
        sceneService.createScene(scene);
        return ResultUtil.success();
    }

    @PostMapping("/update")
    public ResultUtil update(@RequestBody Scene scene) {
        sceneService.updateScene(scene);
        return ResultUtil.success();
    }

    @PostMapping("/delete")
    public ResultUtil delete(@RequestParam("id") List<Integer> id) {
        sceneService.deleteScene(id);
        return ResultUtil.success();
    }

    /**
     * 获取除了传来id之外的场景
     */
    @GetMapping("/getOther/{id}")
    public ResultUtil getOtherById(@PathVariable("id") Integer id) {
        Assert.notNull(id, "id不能为空");
        return ResultUtil.success(sceneService.getOtherById(id));
    }

}
